import moment from 'moment';

export default (value, formatStr = 'YYYY-MM-DD HH:mm:ss') => {
  const targetValue = parseInt(value, 10);
  if (Number.isNaN(targetValue)) {
    return '';
  }
  let targetFormatStr = formatStr;
  if (typeof formatStr === 'boolean') {
    if (formatStr === true) {
      targetFormatStr = 'YYYY-MM-DD';
    }
  }
  const date = moment(targetValue);
  if (date.isValid()) {
    return moment(targetValue).format(targetFormatStr);
  }
  return '';
};
